package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.ruoyi.system.domain.vo.EnrollStudentPageVO;
import com.ruoyi.system.domain.vo.StudentContactInfoListVO;
import com.ruoyi.system.domain.vo.StudentContactInfoVO;
import com.ruoyi.system.mapper.StudentContactInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.EnrollStudentInfoMapper;
import com.ruoyi.system.domain.EnrollStudentInfo;
import com.ruoyi.system.service.IEnrollStudentInfoService;

/**
 * 报名学生基础信息Service业务层处理
 *
 * @author ruoyi
 * @date 2025-05-08
 */
@Service
public class EnrollStudentInfoServiceImpl implements IEnrollStudentInfoService {
    @Autowired
    private EnrollStudentInfoMapper enrollStudentInfoMapper;

    @Autowired
    private StudentContactInfoMapper studentContactInfoMapper;

    /**
     * 查询报名学生基础信息
     *
     * @param id 报名学生基础信息主键
     *
     * @return 报名学生基础信息
     */
    @Override
    public EnrollStudentInfo selectEnrollStudentInfoById(Long id) {
        return enrollStudentInfoMapper.selectEnrollStudentInfoById(id);
    }

    /**
     * 查询报名学生基础信息列表
     *
     * @param enrollStudentInfo 报名学生基础信息
     *
     * @return 报名学生基础信息
     */
    @Override
    public List<EnrollStudentPageVO> selectEnrollStudentInfoList(EnrollStudentInfo enrollStudentInfo) {
        List<EnrollStudentPageVO> list = enrollStudentInfoMapper.selectEnrollStudentInfoList(enrollStudentInfo);
        return list;
    }

    /**
     * 新增报名学生基础信息
     *
     * @param enrollStudentInfo 报名学生基础信息
     *
     * @return 结果
     */
    @Override
    public int insertEnrollStudentInfo(EnrollStudentInfo enrollStudentInfo) {
        return enrollStudentInfoMapper.insertEnrollStudentInfo(enrollStudentInfo);
    }

    /**
     * 修改报名学生基础信息
     *
     * @param enrollStudentInfo 报名学生基础信息
     *
     * @return 结果
     */
    @Override
    public int updateEnrollStudentInfo(EnrollStudentInfo enrollStudentInfo) {
        return enrollStudentInfoMapper.updateEnrollStudentInfo(enrollStudentInfo);
    }

    /**
     * 批量删除报名学生基础信息
     *
     * @param ids 需要删除的报名学生基础信息主键
     *
     * @return 结果
     */
    @Override
    public int deleteEnrollStudentInfoByIds(Long[] ids) {
        return enrollStudentInfoMapper.deleteEnrollStudentInfoByIds(ids);
    }

    /**
     * 删除报名学生基础信息信息
     *
     * @param id 报名学生基础信息主键
     *
     * @return 结果
     */
    @Override
    public int deleteEnrollStudentInfoById(Long id) {
        return enrollStudentInfoMapper.deleteEnrollStudentInfoById(id);
    }

    @Override
    public List<StudentContactInfoListVO> getStudentContact(Long studentId) {
        StudentContactInfoVO studentContact = studentContactInfoMapper.getStudentContactByStudentId(studentId);
        List<StudentContactInfoListVO> vos=new ArrayList<>(3);
        if (Objects.isNull(studentContact)) {
            studentContact=new StudentContactInfoVO();
        }
        StudentContactInfoListVO self=StudentContactInfoListVO.builder()
                .relationWithSelf("本人")
                .mobile(studentContact.getMobile()).qq(studentContact.getQq()).name(studentContact.getStudentName())
                .wechat(studentContact.getWechat()).build();

        vos.add(self);
        StudentContactInfoListVO father=StudentContactInfoListVO.builder()
                .relationWithSelf("父亲")
                .name(studentContact.getFatherName())
                .mobile(studentContact.getFatherMobile())
                .qq(studentContact.getFatherQq()).wechat(studentContact.getFatherWechat()).build();

        StudentContactInfoListVO mother=StudentContactInfoListVO.builder()
                .relationWithSelf("母亲")
                .name(studentContact.getMotherName())
                .mobile(studentContact.getMotherMobile())
                .qq(studentContact.getMotherQq()).wechat(studentContact.getMotherWechat()).build();

        vos.add(father);
        vos.add(mother);
        return vos;
    }
}
